package zhoufu.sz.sanxiao_check.ui;

import android.databinding.ViewDataBinding;
import android.view.View;
import javax.inject.Inject;
import zhoufu.sz.sanxiao_check.R;
import zhoufu.sz.sanxiao_check.databinding.ActivityModifyPasswordBinding;
import zhoufu.sz.sanxiao_check.inject.components.DaggerLoginComponet;
import zhoufu.sz.sanxiao_check.inject.components.LoginComponet;
import zhoufu.sz.sanxiao_check.models.BaseModel;
import zhoufu.sz.sanxiao_check.presents.ModifyPassPresenter;
import zhoufu.sz.sanxiao_check.ui.contract.BasicMsgItem2Contract;
import zhoufu.sz.sanxiao_check.utils.UIUtils;

/**
 * User:RCP
 * email:ruancaipu@gmail.com
 * Date:2016/8/8
 * 修改密码
 */
public class ModifyPasswordActivity extends BaseActivity implements BasicMsgItem2Contract.View,
        View.OnClickListener
{

    private ActivityModifyPasswordBinding _binding;

    @Inject
    ModifyPassPresenter _presenter;

    @Override protected void initInject()
    {
        LoginComponet componet = DaggerLoginComponet.builder().appComponent(getAppComponent())
                .activityModule(getActivityModule()).build();
        componet.inject(this);
        setTitle(R.string.title_change_pass);
        _presenter.bindView(this);
    }

    @Override protected void initAfterOnCreate(ViewDataBinding binding)
    {
        _binding = (ActivityModifyPasswordBinding) binding;
        _binding.setOnclickListener(this);
    }

    @Override protected int setIndividualId()
    {
        return R.layout.activity_modify_password;
    }

    @Override public String SID()
    {
        return null;
    }

    @Override public void setModel(BaseModel baseModel)
    {

    }

    @Override public void updateSuccese()
    {
        UIUtils.showToast(this, UIUtils.getString(R.string.modify_success));
        finish();
    }

    @Override public void showToast(String msg)
    {
        UIUtils.showSnackbar(_binding.getRoot(), msg);
    }

    @Override public void pullFaild()
    {
        UIUtils.showSnackbar(_binding.getRoot(), R.string.toast_network_error);
    }

    @Override public void pullEnd()
    {
        hideProgreesDialog();
    }

    @Override public void pullStart()
    {
        showProgreesDialog();
    }

    @Override public void onClick(View v)
    {
        if ( v.getId() == R.id.commit )
        {
            _presenter.commit(_binding.etOldPassword.getText().toString(),
                    _binding.etNewPassword.getText().toString(),
                    _binding.etReNewPassword.getText().toString());
        }
    }
}
